// 获取雷达图的option
export const getRadarOption = (type = 0, radarData= {})=>{
    let datas = [
        {
            indicator:  [
                {
                    text: '神经',
                    max: 10
                },
                {
                    text: '运动',
                    max: 10
                },
                {
                    text: '生殖',
                    max: 10,
                },
                {
                    text: '泌尿',
                    max: 10
                },
                {
                    text: '消化',
                    max: 10
                },
                {
                    text: '呼吸',
                    max: 10
                },
                {
                    text: '循环',
                    max: 10
                },
                {
                    text: '内分泌',
                    max: 10
                }
            ],
            lineStyleColor: 'rgba(128, 225, 186, 0.2)',
            splitLineColor: 'rgba(93, 161, 245, 0.08)',
            areaStyleColor: [ '#B0EDD2', '#BDEFD9', '#CAF2E1', '#DAF6EA', '#EBFBF4'],
            seriesAreaStyleColor : 'rgba(81, 206, 156, 0.3)',
            itemColor: '#10CA7D'
        },
        {
            indicator:  [
                {
                    text: '阴',
                    max: 10
                },
                {
                    text: '实',
                    max: 10
                },
                {
                    text: '热',
                    max: 10,
                },
                {
                    text: '里',
                    max: 10
                },
                {
                    text: '阳',
                    max: 10
                },
                {
                    text: '虚',
                    max: 10
                },
                {
                    text: '寒',
                    max: 10
                },
                {
                    text: '表',
                    max: 10
                }
            ],
            lineStyleColor: 'rgba(129, 77, 255, 0.1)',
            areaStyleColor:[ '#DDD0FF', '#E1D8FA', '#E8E2FE', '#EFECFF', '#F6F5FE'],
            splitLineColor: 'rgba(221, 208, 255, 0.1)',
            seriesAreaStyleColor : 'rgba(176, 148, 255, 0.3)',
            itemColor: '#814DFF'
        },
        {
            indicator:  [
                {
                    text: '焦虑',
                    max: 10
                },
                {
                    text: '紧张',
                    max: 10
                },
                {
                    text: '疲劳',
                    max: 10,
                },
                {
                    text: '压力',
                    max: 10
                },
                {
                    text: '抑郁',
                    max: 10
                }
            ],
            lineStyleColor: 'rgba(93, 161, 245, 0.08)',
            areaStyleColor:[ '#A2D6FF', '#AEDBFF', '#C2E3FE', '#D3EBFE', '#E7F4FE'],
            splitLineColor: 'rgba(128, 225, 186, 0.2000)',
            seriesAreaStyleColor : 'rgba(0, 145, 255, 0.2)',
            itemColor: '#529CD2'
        }
    ]
    let options = {
        grid: {
            top: 30,
            left: 30,
            bottom: 30,
            right: 30,
            containLabel: true
        },
        radar: {
            name: {
                show: true,
                textStyle: {
                    color: '#414F5B',
                    fontSize: 10
                },
            },
            splitNumber: 4,
            nameGap: 3,
            indicator: radarData.indicator || datas[type].indicator,
            axisLine: { //指向外圈文本的分隔线样式
                lineStyle: {
                    color: datas[type].lineStyleColor,
                }
            },
            splitLine: {
                lineStyle: {
                    color: datas[type].splitLineColor, // 分隔线颜色
                    width: 1, // 分隔线线宽
                }
            },
            splitArea: {
                areaStyle: {
                    color: datas[type].areaStyleColor,
                    opacity: 0.7 // 区域透明度
                },
            },
            radius: '70%',
        },
        series: [
            {
                type: 'radar',
                symbolSize: 5,
                symbol: 'circle',
                hoverAnimation: false,
                silent: true,
                itemStyle: {
                    normal: {
                        label: {
                            show: false,
                            formatter: function (params) {
                                return params.value;
                            },
                            color: '#ffffff',
                            fontSize: 12,
                            fontFamily: 'DINPro',
                            align: 'center',
                            distance: 0,
                        },
                        color: datas[type].itemColor,
                        borderColor: '#fff',
                        borderWidth: 1,
                    }
                },
                lineStyle: {
                    type: 'dashed',
                    width: 1
                },
                areaStyle: {
                    color: datas[type].seriesAreaStyleColor
                },
                data: [
                    {
                        value: radarData.value || [],
                        name: '数',
                        lineStyle: {
                            color: datas[type].itemColor, //设置折线的颜色
                        },
                    }
                ]
            }
        ]
    }
    return options
}

export const getRadarData = (arr) =>{
    if(!arr) return
    let indicator = []
    let value = []
    if (arr && arr.length) {
        arr.map((val)=>{
            indicator.push({
                text: val.name,
                max: 10
            })
            value.push(val.value)
        })
    }
    return {
        indicator: indicator,
        value: value
    }
}
// 获取曲线图的option
export const getLineOption = (data , dataT)=>{
    let yAxis =  [{
        name: data.danwei|| '',
        type: 'value',
        scale: true,
        splitNumber: 10,
        nameTextStyle: {
            color: 'rgba(28, 28, 30, 1)'
        },
        axisTick:{
            show:true, // 刻度
            lineStyle: {
                color: 'rgba(228, 235, 255, 1)'
            },
            inside: true
        } ,
        axisLabel:{
            color:'rgba(28, 28, 30, 0.6)',
            margin: 3,
            formatter:(val)=>{
                if(val > 1000) {
                    return Math.round(val / 100) / 10 + 'k'
                } else {
                    return val
                }
            },
        },
        axisLine: {
            show: true,
            lineStyle: {
                color: 'rgba(228, 235, 255, 1)'
            }
        },
        splitLine: {
            show: false,
        },
        min: data.minValue|| 0
        // max: data.maxValue
    }]
    let series = [{
        name: data.name,
        type: 'line',
        label:{
            show: false,
            color: 'rgba(28, 28, 30, 0.8)',
            align: 'center',
            lineHeight: 20,
            backgroundColor: '#E4EBFF' ,
            borderColor:'#8AA8FD' ,
            borderWidth: 1 ,
            borderType: 'solid' ,
            borderRadius:10 ,
            padding:[0, 10],
        },
        color: 'rgba(39, 95, 253, 1)',
        data: data.value,
        lineStyle: {
            width: 1
        },
        itemStyle: {},
        markArea: {
            itemStyle: {
                color: 'rgba(224, 241, 255, 0.7)' //背景色
            },
            data: [
                [
                    {
                        yAxis: data.min
                    },
                    {
                        yAxis: data.max
                    }
                ]
            ]
        }
    }]
    if(dataT) {
        yAxis.push( {
            name: dataT.danwei|| '',
            type: 'value',
            scale: true,
            splitNumber: 10,
            nameTextStyle: {
                color: 'rgba(28, 28, 30, 1)'
            },
            axisTick:{
                show:true, // 刻度
                lineStyle: {
                    color: 'rgba(228, 235, 255, 1)'
                },
                inside: true
            } ,
            axisLabel:{
                color:'rgba(28, 28, 30, 0.6)',
                margin: 3,
                formatter:(val)=>{
                    if(val > 1000) {
                        return Math.round(val / 100) / 10 + 'k'
                    } else {
                        return val
                    }
                },
            },
            axisLine: {
                show: true,
                lineStyle: {
                    color: 'rgba(228, 235, 255, 1)'
                }
            },
            splitLine: {
                show: false
            },
            min: dataT.minValue || 0,
            // max: dataT.maxValue
        })
        // XYZBXY001007 体重 不展示正常区间
        let markArea = dataT.quotaCode === 'XYZBXY001007' ? null :  {
            itemStyle: {
                color: 'rgba(253, 147, 39, 0.1)' //背景色
            },
            data: [
                [
                    {
                        yAxis: dataT.min
                    },
                    {
                        yAxis: dataT.max
                    }
                ]
            ]
        }
        series.push( {
            name: dataT.name,
            type: 'line',
            label:{
                show: false,
                color: 'rgba(28, 28, 30, 0.8)',
                align: 'center',
                lineHeight: 20,
                backgroundColor: '#E4EBFF' ,
                borderColor:'#8AA8FD' ,
                borderWidth: 1 ,
                borderType: 'solid' ,
                borderRadius:10 ,
                padding:[0, 10],
            },
            color: 'rgba(253, 147, 39, 1)',
            yAxisIndex: 1,
            lineStyle: {
                width: 1
            },
            data: dataT.value,
            markArea: markArea
        })
    }
    let options = {
        title: {
            text: ''
        },
        tooltip: {
            className: 'chartTooltip',
            trigger: 'axis',
            textStyle: {
                fontSize: 10
            },
            position: ['35%', '15%'],
            formatter: (params) =>{
                let res = ''
                if(params && params.length) {
                    params.map((val)=>{
                        res += `<div class="tipBox">${val.marker}<span class="tipName">${val.seriesName}</span>${val.value}</span></div>`
                    })
                }
                return res
            }
        },
        legend: {
            bottom: 10,
            itemWidth: 15,
            itemHeight: 8,
            textStyle: {
                fontSize: 10
            }
        },
        grid: {
            width: '83.3%',
            left: '8.5%',
            top: '12%',
            bottom: 70
        },
        xAxis: {
            type: 'category',
            data: data.nameArr,
            axisTick: {
                alignWithLabel: true,
                interval: 0,
                inside: true
            },
            lineStyle: {
                color: 'rgba(228, 235, 255, 1)'
            },
            axisLine: {
                lineStyle: {
                    color: 'rgba(228, 235, 255, 1)'
                }
            },
            axisLabel:{
                color:'rgba(28, 28, 30, 0.6)',
                fontSize: 10
            },
        },
        yAxis: yAxis,
        series: series
    }
    return options
}
// 处理曲线图的数据 超出区间给红色显示
export const doLineChartData = (data) => {
    let resArr = {
        nameArr: [],
        value: []
    }
    let arr = data.quotas || []
    let max =data.normalMaxValue ? Number(data.normalMaxValue) : null
    let min =data.normalMinValue ? Number(data.normalMinValue) : null
    arr.map((val)=>{
        if (min && max && (val.value< min || val.value > max)) {
            resArr.value.push({
                value:val.value,
                label:{
                    color: 'rgba(28, 28, 30, 0.8)',
                    backgroundColor: 'rgba(255, 228, 228, 1)' ,
                    borderColor:'rgba(253, 138, 138, 1)' ,
                },
                itemStyle: {
                    color: '#FD2E27'
                },
                unit: data.unit
            })
        } else {
            resArr.value.push({
                value: val.value,
                unit: data.unit
            })
        }
        let xStr = (val.date || '').replace(/-/g, '/').substr(2)
        resArr.nameArr.push(xStr)
    })
    resArr.maxValue = data.maxValue ? Number(data.maxValue): null
    resArr.minValue = data.minValue? Number(data.minValue): null
    resArr.max= max
    resArr.min= min
    resArr.danwei= data.unit || ''
    resArr.name = data.quotaName || ''
    resArr.quotaCode = data.quotaCode || ''
    return resArr
}

export const raderChar = (indicator) => {
    return {
        color: ['#FF9C3C','#2AD36A','#2150D4'],
        grid: {
            top: 30,
            left: 30,
            bottom: 30,
            right: 30,
            containLabel: true
        },
        radar: {
            name: {
                show: true,
                formatter(value, indicator) {
                    return `{a|${value}}\n${indicator.max}g`
                },
                fontSize: 13,
                color: '#222222',
                fontWeight: 'bold',
                rich: {
                    a: {
                        color: 'rgba(34,34,34,0.6)',
                        fontWeight: 'normal'
                    }
                }
            },
            splitNumber: 4,
            indicator: [],
            axisLine: { //指向外圈文本的分隔线样式
                show: false,
                lineStyle: {
                    type: 'dashed',
                    color: 'rgba(93, 161, 245, 0.3)',
                }
            },
            splitLine: {
                show: false,
                lineStyle: {
                    color: 'rgba(93, 161, 245, 0.08)', // 分隔线颜色
                    width: 1, // 分隔线线宽
                }
            },
            splitArea: {
                areaStyle: {
                    color: [
                        'rgba(240, 250, 255, 1)',
                        'rgba(226, 238, 255, 1)',
                        'rgba(218, 232, 252, 1)',
                        'rgba(204, 225, 255, 1)'
                    ].reverse(),
                    opacity: 0.7 // 区域透明度
                },
            },
            radius: '70%',
        },
        series: [
            {
                type: 'radar',
                hoverAnimation: false,
                silent: true,
                data: [
                    {
                        value: [],
                        name: '白色线',
                        symbolSize: 0,
                        symbol: 'circle',
                        lineStyle: {
                            type: 'dashed',
                            width: 1,
                            color: '#ffffff'
                        },
                        label: {
                            show: false,
                        }
                    },
                    {
                        value: [10, 10, 10, 10, 10, 10],
                        name: '最大摄入量',
                        symbolSize: 0,
                        symbol: 'circle',
                        lineStyle: {
                            type: 'dashed',
                            width: 2,
                            color: '#FF9C3C'
                        }
                    },
                    {
                        value: [5,5,5,5,5,5],
                        name: '目标摄入量',
                        symbolSize: 0,
                        symbol: 'circle',
                        lineStyle: {
                            type: 'dashed',
                            width: 2,
                            color: '#2AD36A'
                        },
                        label: {
                            show: true,
                            fontWeight: 'bold',
                            formatter: '{c}g',
                            position: 'bottom',
                            distance: 2
                        }
                    },
                    {
                        value: [2, 6, 3, 5, 7, 9],
                        name: '实际摄入量',
                        symbolSize: 5,
                        symbol: 'circle',
                        lineStyle: {
                            width: 0
                        },
                        areaStyle: {
                            color: '#7292FE'
                        },
                        itemStyle: {
                            normal: {
                                color: '#ffffff',
                                borderColor: '#306BFF',
                                borderWidth: 1,
                            }
                        },
                    }
                ]
            }
        ]
    }
}
